
var feeds = new Set();


$('.content').feeds({
 
  feeds: {
   asfar: 'http://www.alyaoumia.com/feeds/posts/default?alt=rss',
    asfart: 'http://www.th3professional.com/feeds/posts/default?alt=rss',
   
  },
  
  preprocess: function ( feed ) {

    feeds.add(feed);

   
    var rssParam = getUrlParameter('feed');
    
  
    if(rssParam == undefined) {
      
      
      var today = new Date();
      var pubDate = new Date(this.publishedDate);
      var during = today.getTime() - pubDate.getTime();
      if(during > 14 * 24 * 60 * 60 * 1000) { 
        return false;
      }
    }
   
    else {
      // display only one source
      if(rssParam !== feed.feedUrl) {
        return false;
      }
    }
  },
 
  entryTemplate: function(entry) {
    
    var template = 
        '<div class="entry">' +
          '<div><span><!=feedTitle!></span></div>' +
          '<div><span><!=publishedDate!></span></div>' +
          '<div><a href="<!=link!>" target="_blank"><h3><!=title!></h3></a></div>' +
          '<div><p><!=contentSnippet!></p></div>' +
        '</div>';
    
    return this.tmpl(template, entry);
  },
  
  onComplete: function(entries) {

    feeds.forEach(function(item){
      var menuDom = '<core-item><div><a href="?feed=' + item.feedUrl + '">'+ item.title + '</a></div></core-item>';
      $('#menu').append(menuDom);
    });    
  }
});


function getUrlParameter(sParam)
{
  var sPageURL = window.location.search.substring(1);
  var sURLVariables = sPageURL.split('&');
  for (var i = 0; i < sURLVariables.length; i++)
  {
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == sParam)
    {
      return sParameterName[1];
    }
  }
}